package com.black.knight.chess.adapters;

import android.content.Context;
import android.graphics.PorterDuff.Mode;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.black.knight.chess.R;
import com.black.knight.chess.model.SPModel;

public class SPDestroyedFiguresAdapter extends BaseAdapter {
    private Context mContext;
    
    private boolean white;

    public boolean isWhite() {
		return white;
	}

	public void setWhite(boolean white) {
		this.white = white;
	}

	public SPDestroyedFiguresAdapter(Context c, boolean white) {
        mContext = c;
        this.white = white;
    }

    public int getCount() {
    	Integer[] figures = SPModel.getInstance().getDestroyedFiguresWhite();    	
    	if(!white) figures = SPModel.getInstance().getDestroyedFiguresBlack();
    	
    	return figures.length;
    }

    public Integer getItem(int position) {
    	Integer[] figures = SPModel.getInstance().getDestroyedFiguresWhite();    	
    	if(!white) figures = SPModel.getInstance().getDestroyedFiguresBlack();
    	
    	return figures[position];
    }

    public long getItemId(int position) {
        return 0;
    }

    // create a new ImageView for each item referenced by the Adapter
    public View getView(int position, View convertView, ViewGroup parent) {
    	ImageView imageView = (ImageView) LayoutInflater.from(mContext).inflate(R.layout.sp_destroyed_figure, parent, false);
        
        
    	Integer[] figures = SPModel.getInstance().getDestroyedFiguresWhite();    	
    	if(!white) figures = SPModel.getInstance().getDestroyedFiguresBlack();
        
        if(figures.length > position) {
        	imageView.setImageResource(figures[position]);
            if(white && position == SPModel.getInstance().getSelectedFlagWhite()) {
            	imageView.setColorFilter(mContext.getResources().getColor(R.color.green), Mode.DST_ATOP);
            } else if(!white && position == SPModel.getInstance().getSelectedFlagBlack()) {
            	imageView.setColorFilter(mContext.getResources().getColor(R.color.green), Mode.DST_ATOP);
            }
        }
                
        return imageView;
    }
}